﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Sort_puzur
{
    class Program
    {
        static void ArrNumb(int[] arr)
        {
            //  int[] arr = { 15, 10, 5, 20, 30 };
            for (int i = 1; i < arr.Length; i++)
            {
                for (int j = arr.Length - i - 1; j < arr.Length - 1; j++)
                {
                    if (arr[j] > arr[j + 1])
                    {
                        int temp = arr[j];
                        arr[j] = arr[j + 1];
                        arr[j + 1] = temp;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
        static void Output(int[] arr)
        {
            foreach (int i in arr)
            {
                Console.Write(i + " ");
            }
        }
        static int Arr1Letters(string s, char[] arr1, char d)
        {
            int alg = 0;
            for (int i = 1; i < arr1.Length; i++)
            {
                for (int j = arr1.Length - i - 1; j < arr1.Length - 1; j++)
                {
                    if (arr1[j] > arr1[j + 1])
                    {
                        d = arr1[j];
                        arr1[j] = arr1[j + 1];
                        arr1[j + 1] = d;
                    }
                    else
                    {
                        break;
                    }
                    alg++;
                }
            }
            return alg;
        }
        static void OutputLet(char[] arr1, int alg)
        {
            for (int i = 0; i < arr1.Length; i++)
            {
                Console.Write(arr1[i] + " ");
            }
            Console.WriteLine();
            Console.WriteLine(alg);
        }
        static void Compare(string s1, string str, string[] strarr)
        {
          
            for (int i = 1; i < strarr.Length; i++)
            {
                for (int j = strarr.Length - i - 1; j < strarr.Length - 1; j++)
                {

                    if (strarr[j].CompareTo(strarr[j + 1]) > 0)
                    {
                        s1 = strarr[j];
                        strarr[j] = strarr[j + 1];
                        strarr[j + 1] = s1;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
        static void OutputWords(string[] strarr)
        {
            Console.WriteLine();
            foreach (string s3 in strarr)
            {
                Console.Write(s3 + " ");
            }
        }
        static void Main(string[] args)
        {
            int[] arr = { 15, 10, 5, 20, 30 };
            ArrNumb(arr);

            Output(arr);
            Console.WriteLine();
            string s = "щъыьэюяабвгдопрстуфхцчшежзийклмн";
            char[] arr1 = s.ToCharArray();
            char d = ' ';
            int alg = Arr1Letters(s, arr1, d);
            OutputLet(arr1, alg);

            string s1 = "";
            string str = "ааа ссс ббб ддд ввв";
            string[] strarr = str.Split();
            Compare(s1, str, strarr);
            OutputWords(strarr);
        }
    }
}